package xhwl.insurance.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import xhwl.insurance.R;
import xhwl.insurance.http.bean.resp.SalesCardData;

/**
 * 售卡页面左侧详细的adapter
 */

public class SaleCardMenuListAdapter extends BaseAdapter {
    Context context;
    List<SalesCardData> list;
    private int defItem;//声明默认选中的项

    public SaleCardMenuListAdapter(Context context, List<SalesCardData> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setDefSelect(int position) {
        this.defItem = position;
        notifyDataSetChanged();
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_menulist, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (defItem == position) {
            convertView.setBackgroundColor(Color.parseColor("#f7f7f7"));
            holder.name_menu.setTextColor(Color.parseColor("#4585ef"));
        } else {
            convertView.setBackgroundResource(R.color.white);
            holder.name_menu.setTextColor(Color.BLACK);
        }
        holder.name_menu.setText(list.get(position).getYw_name());
        return convertView;
    }


    public static class ViewHolder {
        public View rootView;
        public TextView name_menu;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.name_menu = (TextView) rootView.findViewById(R.id.name_menu);
        }

    }
}
